'use strict';
exports.main = async (event, context) => {
  const { species_id, content, user_info } = event;
  const db = uniCloud.database();
  
  try {
    const comment = {
      content,
      username: user_info.username || '匿名用户',
      avatar: user_info.avatar,
      createTime: Date.now(),
      species_id
    };
    
    const result = await db.collection('comments').add(comment);
    
    return {
      code: 200,
      message: '评论成功',
      data: {
        ...comment,
        _id: result.id
      }
    }
  } catch (error) {
    return {
      code: 500,
      message: error.message || '评论失败'
    }
  }
}; 